function yzCurrying(fn) {
  function curried(...args) {
    if(fn.length <= args.length) {
      return fn.apply(this, args);
    } else {
      function curried2(...args2) {
        const result = curried.apply(this, [...args, ...args2]);
        return result;
      }
      return curried2;
    }
  }

  return curried;
}

function sum(num1, num2, num3, num4) {
  console.log(num1 + num2 + num3 + num4);
}

var curriedSum = yzCurrying(sum);

curriedSum(10, 20)(30, 40);
curriedSum(10)(10)(10)(10);
curriedSum(10, 20, 30)(10);